//
//  AppDelegate+JPush.m
//  CoreJPush
//
//  Created by 冯成林 on 15/9/17.
//  Copyright (c) 2015年 冯成林. All rights reserved.
//

#import "AppDelegate+JPush.h"
#import "JPUSHService.h"
#import "CoreJPush.h"

@implementation AppDelegate (JPush)


- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    
    // Required
    [JPUSHService registerDeviceToken:deviceToken];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    
    // Required,For systems with less than or equal to iOS6
    [JPUSHService handleRemoteNotification:userInfo];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

    // IOS 7 Support Required
    [JPUSHService handleRemoteNotification:userInfo];
    completionHandler(UIBackgroundFetchResultNewData);
    
    CoreJPush *jpush = [CoreJPush sharedCoreJPush];
    [jpush didReceiveRemoteNotification:userInfo];
    
    NSLog(@"消息数：%@",EXRACT_OBJECT(NEWSCOUNT));
    if (EXRACT_OBJECT(NEWSCOUNT) == nil)
    {
        SAVE_OBJECT(@"1", NEWSCOUNT);
    }
    else
    {
        NSString *count = [NSString stringWithFormat:@"%i",[EXRACT_OBJECT(NEWSCOUNT) intValue] +1];
        SAVE_OBJECT(count, NEWSCOUNT);
    }
    
    if (userInfo[@"aps"] && userInfo[@"aps"][@"alert"]) {
//        [[AlertViewManager shareManager] initWithMessage:userInfo[@"aps"][@"alert"] cancleButtonTitle:@"确定" clickAtIndex:^(NSInteger buttonIndex, UIAlertController *alertController) {
//            
//        }];
    }
}


@end
